import numpy as np
import pandas as pd

np.random.seed(1)
X = np.random.randint(1, 10, size=30)
A = X.reshape(-1,3)
print('X的3列矩阵为:\n{}'.format(A))
a = A[:,2:3]
a[np.argwhere(a <= 3)[:,0]] = 0
a[np.argwhere((a > 3) & (a <= 6))[:,0]] = 1
a[np.argwhere(a > 6)[:,0]] = 2
print('矩阵第三列样本化:\n{}'.format(A))
b = A[:,2:3]
ind = np.argwhere(b == 0)[:,0]
B0 = A[ind,0:2]
ind = np.argwhere(b == 1)[:,0]
B1 = A[ind,0:2]
ind = np.argwhere(b == 2)[:,0]
B2 = A[ind,0:2]
print('样本分离后:')
print('样本0:\n{}'.format(B0))
print('样本1:\n{}'.format(B1))
print('样本2:\n{}'.format(B2))
